package com.my.test.aop.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
import org.springframework.stereotype.Component;

import com.my.test.aop.Apology;
import com.my.test.aop.impl.ApologyImpl;

/**
 * 用aspectJ注解来实现引入增强
 * 
 * @author Administrator
 * 
 */
@Aspect
@Component
public class GreetingAspect {

	// 引入增强
	@DeclareParents(value = "com.my.test.aop.impl.GreetingImpl", defaultImpl = ApologyImpl.class)
	private Apology apology;

	// 拦截注解
	@Around("@annotation(com.my.test.aop.annotation.Tag)")
	public Object around(ProceedingJoinPoint pjp) throws Throwable {
		System.out.println("before");
		Object result = pjp.proceed();
		System.out.println("after");
		
		return result;
	}

	public Apology getApology() {
		return apology;
	}

	public void setApology(Apology apology) {
		this.apology = apology;
	}
}